import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:share_fit/app/controllers/base/base_controller.dart';
import 'package:share_fit/app/helper/ext/tr_ext.dart';
import 'package:share_fit/app/models/home/sleep_model.dart';
import 'package:share_fit/app/tools/date_tool.dart';
import 'package:share_fit/generated/locales.g.dart';

import 'state.dart';

class NapLogic extends BaseController {
  final NapState state = NapState();

  goBackSleepPage() {
    Get.back();
  }

  @override
  String getRemotePath() {
    throw '';
  }

  @override
  void initState() {
    state.sm = Get.arguments ?? SleepModel();
  }

  @override
  void onRemoteEvent(event, method) {
    // TODO: implement onRemoteEvent
  }

  String getPercentValueText() {
    return DateTool.second2HM((state.sm.sleepTime ?? 0) * 60);
  }

  /// 小睡参考值计算:清醒:0-40分钟为正常，大于40分钟为偏高。
  getLevelText() {
    int st = state.sm.sleepTime ?? 0;
    if (st <= 40) {
      return Text(LocaleKeys.sleep_ratio_normal.ts, style: TextStyle(color: Colors.white, fontSize: 48.sp));
    } else {
      return Text(LocaleKeys.sleep_ratio_height.ts, style: TextStyle(color: Colors.white, fontSize: 48.sp));
    }
  }

  getContainerColor() {
    int st = state.sm.sleepTime ?? 0;
    if (st <= 40) {
      return Colors.green;
    } else {
      return Colors.red;
    }
  }
}
